package com.mail.transfer.email.schedule;

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.support.CronTrigger;

/**
 * @author xiaocg
 */
public class DynamicTimedTask {

    private MailPullScheduledTask mailPullScheduledTask;

    public DynamicTimedTask(MailPullScheduledTask mailPullScheduledTask) {
        this.mailPullScheduledTask = mailPullScheduledTask;
    }

    /**
     * 启动定时任务
     * @return
     */
    public void startCron() {
        String cron = "0 0/5 * * * ?";
        ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
        threadPoolTaskScheduler.initialize();
        threadPoolTaskScheduler.schedule(mailPullScheduledTask, new CronTrigger(cron));
    }

}
